package com.ruoyi.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.plus.web.controller.BasePlusController;
import com.ruoyi.common.core.plus.web.page.PageDto;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysMenuLanguage;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysMenuLanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单语言Controller
 *
 * @author ruoyi
 * @date 2022-04-26
 */
@RestController
@RequestMapping("/system/menu_language")
public class SysMenuLanguageController extends BasePlusController {
    @Autowired
    private ISysMenuLanguageService sysMenuLanguageService;

    /**
     * 查询菜单语言列表
     */
    @PreAuthorize("@ss.hasPermi('system:menuLanguage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMenuLanguage sysMenuLanguage) {
        PageDto pageDto = startPage();
        Page<SysMenuLanguage> page = new Page(pageDto.getCurrentPage(), pageDto.getPageSize());
        Page<SysMenuLanguage> list = sysMenuLanguageService.selectSysMenuLanguageList(page,sysMenuLanguage);
        return getDataTable(list);
    }

    /**
     * 获取菜单语言详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:menuLanguage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysMenuLanguageService.selectSysMenuLanguageById(id));
    }

    /**
     * 新增菜单语言
     */
    @PreAuthorize("@ss.hasPermi('system:menuLanguage:add')")
    @Log(title = "菜单语言", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody SysMenuLanguage sysMenuLanguage) {
        return R.ok(sysMenuLanguageService.insertSysMenuLanguage(sysMenuLanguage));
    }

    /**
     * 修改菜单语言
     */
    @PreAuthorize("@ss.hasPermi('system:menuLanguage:edit')")
    @Log(title = "菜单语言", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody SysMenuLanguage sysMenuLanguage) {
        return R.ok(sysMenuLanguageService.updateSysMenuLanguage(sysMenuLanguage));
    }

    /**
     * 删除菜单语言
     */
    @PreAuthorize("@ss.hasPermi('system:menuLanguage:remove')")
    @Log(title = "菜单语言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(sysMenuLanguageService.deleteSysMenuLanguageById(id));
    }
}